<template>
	<div class="login">

		<div class="login-weaper">
			<div class="login-right">
				<div class="login-main">
					<h4 class="login-title">菁纯记忆管理系统</h4>
					<el-form class="el-form login-form">
						<el-form-item style="margin-left: 0px" prop="userName">
							<el-input type="text" placeholder="请输入账号" prefix-icon="el-icon-user"
								v-model="data.phone" clearable autocomplete="off">
							</el-input>
						</el-form-item>
						<el-form-item style="margin-left: 0px" prop="password">
							<el-input type="password" placeholder="请输入密码" prefix-icon="el-icon-lock"
								v-model="data.pwd" autocomplete="off" :show-password="true">
							</el-input>
						</el-form-item>

						<el-form-item style="margin: 40px 0px 0">
							<el-button id="btn" type="success" class="login-submit" @click="login"
								:loading="loading">
								<span>登录系统</span>
							</el-button>
						</el-form-item>
					</el-form>
				</div>
			</div>
		</div>

		<div class="vue-particles">
			<vue-particles color="#dedede" shapeType="star" linesColor="#dedede" hoverMode="grab" clickMode="push"
				style="height: 100%"></vue-particles>
		</div>
	</div>
</template>

<script>
import { Session } from '@/utils/storage';
import request from '@/utils/request'
export default {
	data() {
		return {
			loading: false,
			data: {
				phone: '',
				pwd: '',
				code: '',
			},
		};
	},
	mounted() { },
	methods: {
		async login() {

			this.loading = true;

			try {
				const res = await request.post('/admin/login', this.data)

				const user = res.userInfo

				if (res) {

					const userInfos = {

						userName: user.name,

						photo: 'https://bapings.oss-cn-beijing.aliyuncs.com/代理/Image/0/202410/daf29a75-52e2-4a86-9e69-eee11f10b916.png',

						time: new Date().getTime(),

						roles: ['admin'],

						authBtnList: [],
					};

					console.log(res, userInfos)

					// // 存储 token 到浏览器缓存
					Session.set('token', res.token);
					// // 存储用户信息到浏览器缓存
					Session.set('userInfo', userInfos);
					// // 存储用户信息到vuex
					this.$store.dispatch('userInfos/setUserInfos', userInfos);
					// PrevLoading.start();
					this.$router.push('/');
				}

			}
			finally {
				this.loading = false;
			}

		},
	}
};
</script>
<style scoped lang="scss">
.login {
	height: 100%;
	width: 100%;
	overflow: hidden;
	display: flex;
	position: relative;

	.vue-particles {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: radial-gradient(ellipse at top left, rgba(105, 155, 200, 1) 0%, rgba(181, 197, 216, 1) 57%);
	}

	.login-weaper {
		margin: auto;
		height: 500px;
		display: flex;
		box-sizing: border-box;
		position: relative;
		z-index: 1;
		border: none;
		box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);

		.login-left {
			width: 491px;
			padding: 20px;
			font-size: 16px;
			color: var(--prev-color-text-white);
			position: relative;
			background-color: var(--prev-color-primary);
			display: flex;
			flex-direction: column;
			border-top-left-radius: 4px;
			border-bottom-left-radius: 4px;

			.login-time {
				width: 100%;
				color: var(--prev-color-text-white);
				opacity: 0.9;
				font-size: 14px;
				overflow: hidden;
			}

			.login-left-box {
				flex: 1;
				overflow: hidden;
				position: relative;
				z-index: 1;
				display: flex;
				align-items: center;
				padding: 80px 45px;

				.logo {
					font-size: 22px;
					margin-bottom: 15px;
				}

				.title {
					color: var(--prev-color-text-white);
					font-weight: 300;
					letter-spacing: 2px;
					font-size: 16px;
				}

				.msg {
					color: var(--prev-color-text-white);
					font-size: 13px;
					margin-top: 35px;

					.msg-author {
						opacity: 0.6;

						span:last-of-type {
							margin-left: 15px;
						}
					}

					.msg-txt {
						margin-top: 15px;
						line-height: 22px;
					}
				}
			}
		}

		.login-right {
			width: 491px;
			padding: 20px;
			position: relative;
			align-items: center;
			display: flex;
			background-color: var(--prev-bg-white);
			border-top-right-radius: 4px;
			border-bottom-right-radius: 4px;

			.login-main {
				margin: 0 auto;
				width: 70%;

				.login-title {
					color: var(--prev-color-text-primary);
					margin-bottom: 40px;
					font-weight: 500;
					font-size: 22px;
					text-align: center;
					letter-spacing: 4px;
				}

				.login-form {
					margin: 10px 0;

					i {
						color: var(--prev-color-text-primary);
					}

					.el-form-item {
						margin-bottom: 20px !important;

						.login-code {
							display: flex;
							align-items: center;
							justify-content: space-around;
							margin: 0 0 0 10px;
							user-select: none;

							.login-code-img {
								margin-top: 2px;
								width: 100px;
								height: 38px;
								border: 1px solid var(--prev-border-color-base);
								color: var(--prev-color-text-primary);
								font-size: 14px;
								font-weight: 700;
								letter-spacing: 5px;
								line-height: 38px;
								text-indent: 5px;
								text-align: center;
								cursor: pointer;
								transition: all ease 0.2s;
								border-radius: 4px;

								&:hover {
									border-color: var(--prev-border-color-hover);
									transition: all ease 0.2s;
								}
							}
						}

						.login-submit {
							width: 100%;
							letter-spacing: 2px;
						}
					}
				}

				.login-menu {
					margin-top: 30px;
					width: 100%;
					text-align: left;

					span {
						color: var(--prev-color-text-secondary);
						font-size: 12px;
						margin: 0 8px;
						text-decoration: none;

						&:hover {
							color: var(--prev-color-primary);
							text-decoration: underline;
						}
					}
				}
			}
		}
	}
}
</style>